{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# Part 5 - Generating Reports"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "toc": true
   },
   "source": [
    "<h1>Table of Contents<span class=\"tocSkip\"></span></h1>\n",
    "<div class=\"toc\"><ul class=\"toc-item\"><li><span><a href=\"#Generating-Reports\" data-toc-modified-id=\"Generating-Reports-1\"><span class=\"toc-item-num\">1&nbsp;&nbsp;</span>Generating Reports</a></span><ul class=\"toc-item\"><li><span><a href=\"#Available-Reports\" data-toc-modified-id=\"Available-Reports-1.1\"><span class=\"toc-item-num\">1.1&nbsp;&nbsp;</span>Available Reports</a></span><ul class=\"toc-item\"><li><span><a href=\"#Reports-Available-for-U.S.\" data-toc-modified-id=\"Reports-Available-for-U.S.-1.1.1\"><span class=\"toc-item-num\">1.1.1&nbsp;&nbsp;</span>Reports Available for U.S.</a></span></li><li><span><a href=\"#Reports-Available-for-Another-Country\" data-toc-modified-id=\"Reports-Available-for-Another-Country-1.1.2\"><span class=\"toc-item-num\">1.1.2&nbsp;&nbsp;</span>Reports Available for Another Country</a></span></li></ul></li><li><span><a href=\"#Creating-Reports\" data-toc-modified-id=\"Creating-Reports-1.2\"><span class=\"toc-item-num\">1.2&nbsp;&nbsp;</span>Creating Reports</a></span><ul class=\"toc-item\"><li><span><a href=\"#Report-for-Single-Line-Address\" data-toc-modified-id=\"Report-for-Single-Line-Address-1.2.1\"><span class=\"toc-item-num\">1.2.1&nbsp;&nbsp;</span>Report for Single Line Address</a></span></li><li><span><a href=\"#Report-for-Buffered-Locations\" data-toc-modified-id=\"Report-for-Buffered-Locations-1.2.2\"><span class=\"toc-item-num\">1.2.2&nbsp;&nbsp;</span>Report for Buffered Locations</a></span><ul class=\"toc-item\"><li><span><a href=\"#Using-options\" data-toc-modified-id=\"Using-options-1.2.2.1\"><span class=\"toc-item-num\">1.2.2.1&nbsp;&nbsp;</span>Using <code>options</code></a></span></li></ul></li><li><span><a href=\"#Report-for-a-Point-Feature\" data-toc-modified-id=\"Report-for-a-Point-Feature-1.2.3\"><span class=\"toc-item-num\">1.2.3&nbsp;&nbsp;</span>Report for a Point Feature</a></span></li><li><span><a href=\"#Report-for-a-Polygon-Study-Area\" data-toc-modified-id=\"Report-for-a-Polygon-Study-Area-1.2.4\"><span class=\"toc-item-num\">1.2.4&nbsp;&nbsp;</span>Report for a Polygon Study Area</a></span></li></ul></li><li><span><a href=\"#Customizing-Reports\" data-toc-modified-id=\"Customizing-Reports-1.3\"><span class=\"toc-item-num\">1.3&nbsp;&nbsp;</span>Customizing Reports</a></span><ul class=\"toc-item\"><li><span><a href=\"#Using-report_fields\" data-toc-modified-id=\"Using-report_fields-1.3.1\"><span class=\"toc-item-num\">1.3.1&nbsp;&nbsp;</span>Using <code>report_fields</code></a></span></li><li><span><a href=\"#Using-use_data\" data-toc-modified-id=\"Using-use_data-1.3.2\"><span class=\"toc-item-num\">1.3.2&nbsp;&nbsp;</span>Using <code>use_data</code></a></span></li></ul></li></ul></li><li><span><a href=\"#Conclusion\" data-toc-modified-id=\"Conclusion-2\"><span class=\"toc-item-num\">2&nbsp;&nbsp;</span>Conclusion</a></span></li></ul></div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Import Libraries\n",
    "from arcgis.gis import GIS\n",
    "from arcgis.geoenrichment import Country, create_report, BufferStudyArea"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Create a GIS Connection\n",
    "gis = GIS(profile='your_online_profile')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Generating Reports"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "GeoEnrichment also enables you to create many types of high quality reports for a variety of use cases describing the input area. These reports can be generated in PDF or Excel formats containing relevant information on demographics, consumer spending, tapestry market, etc. for the area. You can find a sample PDF report [here](https://downloads.esri.com/Support/downloads/other_/geoenrichment/reports/rest-report-samples/ex2.pdf).\n",
    "\n",
    "Find details about a wide variety of existing reports [here](https://doc.arcgis.com/en/esri-demographics/reference/sample-reports.htm)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Available Reports"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "skip"
    }
   },
   "source": [
    "The `reports` property of a `Country` object lists its available reports as a Pandas DataFrame. Let's look at available reports for some countires. The report `id` you see below is used as an input in the `create_report()` method to create reports."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Reports Available for U.S."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Get Country\n",
    "usa = Country.get('USA')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>title</th>\n",
       "      <th>categories</th>\n",
       "      <th>formats</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>census2010_profile</td>\n",
       "      <td>2010 Census Profile</td>\n",
       "      <td>[Demographics]</td>\n",
       "      <td>[pdf, xlsx]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>census2020_profile</td>\n",
       "      <td>2020 Census Profile</td>\n",
       "      <td>[Demographics]</td>\n",
       "      <td>[pdf, xlsx]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>acs_housing</td>\n",
       "      <td>ACS Housing Summary</td>\n",
       "      <td>[Demographics]</td>\n",
       "      <td>[pdf, xlsx]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>acs_keyfacts</td>\n",
       "      <td>ACS Key Population &amp; Household Facts</td>\n",
       "      <td>[Demographics]</td>\n",
       "      <td>[pdf, xlsx]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>acs_population</td>\n",
       "      <td>ACS Population Summary</td>\n",
       "      <td>[Demographics]</td>\n",
       "      <td>[pdf, xlsx]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>55plus</td>\n",
       "      <td>Age 50+ Profile</td>\n",
       "      <td>[Demographics]</td>\n",
       "      <td>[pdf, xlsx]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>agesexrace</td>\n",
       "      <td>Age by Sex by Race Profile</td>\n",
       "      <td>[Demographics]</td>\n",
       "      <td>[pdf, xlsx]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>agesex</td>\n",
       "      <td>Age by Sex Profile</td>\n",
       "      <td>[Demographics]</td>\n",
       "      <td>[pdf, xlsx]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>cex_auto</td>\n",
       "      <td>Automotive Aftermarket Expenditures</td>\n",
       "      <td>[Consumer Spending]</td>\n",
       "      <td>[pdf, xlsx]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>business_loc</td>\n",
       "      <td>Business Locator</td>\n",
       "      <td>[Business]</td>\n",
       "      <td>[pdf]</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   id                                 title  \\\n",
       "0  census2010_profile                   2010 Census Profile   \n",
       "1  census2020_profile                   2020 Census Profile   \n",
       "2         acs_housing                   ACS Housing Summary   \n",
       "3        acs_keyfacts  ACS Key Population & Household Facts   \n",
       "4      acs_population                ACS Population Summary   \n",
       "5              55plus                       Age 50+ Profile   \n",
       "6          agesexrace            Age by Sex by Race Profile   \n",
       "7              agesex                    Age by Sex Profile   \n",
       "8            cex_auto   Automotive Aftermarket Expenditures   \n",
       "9        business_loc                      Business Locator   \n",
       "\n",
       "            categories      formats  \n",
       "0       [Demographics]  [pdf, xlsx]  \n",
       "1       [Demographics]  [pdf, xlsx]  \n",
       "2       [Demographics]  [pdf, xlsx]  \n",
       "3       [Demographics]  [pdf, xlsx]  \n",
       "4       [Demographics]  [pdf, xlsx]  \n",
       "5       [Demographics]  [pdf, xlsx]  \n",
       "6       [Demographics]  [pdf, xlsx]  \n",
       "7       [Demographics]  [pdf, xlsx]  \n",
       "8  [Consumer Spending]  [pdf, xlsx]  \n",
       "9           [Business]        [pdf]  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# print a sample of the reports available for USA\n",
    "usa.reports.head(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(52, 4)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# total number of reports available\n",
    "usa.reports.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can see that there are 52 reports available for United States along with their title, categoriies and the available formats."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Reports Available for Another Country\n",
    "\n",
    "Let's look at the reports available for Australia."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Get Country\n",
    "aus = Country.get('Australia')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>title</th>\n",
       "      <th>categories</th>\n",
       "      <th>formats</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>AustraliaSummaryReport</td>\n",
       "      <td>Australia Summary Report</td>\n",
       "      <td>[Summary Reports]</td>\n",
       "      <td>[pdf, xlsx]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Custom_Map_Landscape</td>\n",
       "      <td>Custom Map Landscape</td>\n",
       "      <td>[Maps]</td>\n",
       "      <td>[pdf]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Custom_Map_Portrait</td>\n",
       "      <td>Custom Map Portrait</td>\n",
       "      <td>[Maps]</td>\n",
       "      <td>[pdf]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>DemographicandIncomeProfileReport</td>\n",
       "      <td>Demographic and Income Profile Report (ABS)</td>\n",
       "      <td>[Demographics]</td>\n",
       "      <td>[pdf, xlsx]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>site_map</td>\n",
       "      <td>Site Map</td>\n",
       "      <td>[Maps]</td>\n",
       "      <td>[pdf]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>site_map_imagery04</td>\n",
       "      <td>Site Map on Satellite Imagery - 0.4 Miles Wide</td>\n",
       "      <td>[Maps]</td>\n",
       "      <td>[pdf]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>site_map_imagery08</td>\n",
       "      <td>Site Map on Satellite Imagery - 0.8 Miles Wide</td>\n",
       "      <td>[Maps]</td>\n",
       "      <td>[pdf]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>site_map_imagery16</td>\n",
       "      <td>Site Map on Satellite Imagery - 1.6 Miles Wide</td>\n",
       "      <td>[Maps]</td>\n",
       "      <td>[pdf]</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                  id  \\\n",
       "0             AustraliaSummaryReport   \n",
       "1               Custom_Map_Landscape   \n",
       "2                Custom_Map_Portrait   \n",
       "3  DemographicandIncomeProfileReport   \n",
       "4                           site_map   \n",
       "5                 site_map_imagery04   \n",
       "6                 site_map_imagery08   \n",
       "7                 site_map_imagery16   \n",
       "\n",
       "                                            title         categories  \\\n",
       "0                        Australia Summary Report  [Summary Reports]   \n",
       "1                            Custom Map Landscape             [Maps]   \n",
       "2                             Custom Map Portrait             [Maps]   \n",
       "3     Demographic and Income Profile Report (ABS)     [Demographics]   \n",
       "4                                        Site Map             [Maps]   \n",
       "5  Site Map on Satellite Imagery - 0.4 Miles Wide             [Maps]   \n",
       "6  Site Map on Satellite Imagery - 0.8 Miles Wide             [Maps]   \n",
       "7  Site Map on Satellite Imagery - 1.6 Miles Wide             [Maps]   \n",
       "\n",
       "       formats  \n",
       "0  [pdf, xlsx]  \n",
       "1        [pdf]  \n",
       "2        [pdf]  \n",
       "3  [pdf, xlsx]  \n",
       "4        [pdf]  \n",
       "5        [pdf]  \n",
       "6        [pdf]  \n",
       "7        [pdf]  "
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# print a sample of the reports available for USA\n",
    "aus.reports.head(20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(8, 4)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# total number of reports available\n",
    "aus.reports.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Creating Reports"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here we see that Australia has 8 reports available along with their title, categories and the available formats. Details about different categories of reports can be found [here](https://doc.arcgis.com/en/esri-demographics/reference/sample-reports.htm)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "The `create_report` method allows you to create many types of high quality reports for a variety of use cases describing the input area. Let's look at some examples of creating reports for some study areas. To learn more about Study Areas, refer to [Enriching Study Areas](../part2-where-to-enrich-study-areas) guide.\n",
    "\n",
    "__Note:__ The report `id` must be used as an input in the `create_report()` method to create reports. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Report for Single Line Address\n",
    "Let's create a report for an address using the Business Summary `business_summary` report id."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'reports\\\\esri_add_business_summary.pdf'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "address_report = create_report(study_areas=[\"380 New York Street, Redlands, CA\"],\n",
    "                     report=\"business_summary\",\n",
    "                     export_format=\"PDF\", \n",
    "                     out_folder=r\"reports\", \n",
    "                     out_name=\"esri_add_business_summary.pdf\")\n",
    "address_report"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can view the `pdf` report in `reports folder` on your disk. Here is a snapshot of how part of your report will look like in Pdf.\n",
    "\n",
    "<img src=\"../../static/img/geoenrich_pdf_sample.jpg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Report for Buffered Locations\n",
    "\n",
    "Reports can also be created for one or more buffered rings, or drive time service areas around the points of interest. Let's create a report for a street address with non-overlapping disks of radii 1, 3 and 5 Miles respectively using the Business Summary report template `report=\"business_summary\"`.\n",
    "\n",
    "We will export this report as a Microsoft Excel file using the `XLSX` export format."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "outputs": [],
   "source": [
    "buffered = BufferStudyArea(area='380 New York St Redlands CA 92373',\n",
    "                           radii=[1,3,5], units='Miles', overlap=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'reports\\\\esri_buffered_business_summary.xlsx'"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "buffered_report = create_report(study_areas=[buffered],\n",
    "                     report=\"business_summary\",\n",
    "                     export_format=\"XLSX\", \n",
    "                     out_folder=r\"reports\", \n",
    "                     out_name=\"esri_buffered_business_summary.xlsx\")\n",
    "buffered_report"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here is a snapshot of how part of your report will look like in Excel.\n",
    "\n",
    "<img src=\"../../static/img/geoenrich_xls_sample.jpg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Using `options`\n",
    "\n",
    "`options` parameter can be specified for the study area buffer. Let's look at an example.\n",
    "\n",
    "__Note:__ By default a 1 mile radius buffer will be applied to points and address locations to define a study area."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Define options\n",
    "area_options={\"areaType\":\"RingBuffer\",\"bufferUnits\":\"esriMiles\",\"bufferRadii\":[1,3,5]}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'reports\\\\studyAreaOptions_business_summary.xlsx'"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Create report\n",
    "areaOptions_report = create_report(study_areas=[\"380 New York Street, Redlands, CA\"],\n",
    "                     report=\"business_summary\",\n",
    "                     export_format=\"XLSX\",\n",
    "                     options= area_options,\n",
    "                     out_folder=r\"reports\", \n",
    "                     out_name=\"studyAreaOptions_business_summary.xlsx\")\n",
    "areaOptions_report"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Report for a Point Feature\n",
    "When a point is used as a study area, the service will automatically create a `1 mile` ring buffer around the point to collect and append enrichment data. We will use the Business Location `business_loc` report to `enrich()` our point feature."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Create point geometry\n",
    "from arcgis.geometry import Point\n",
    "pt = Point({\"x\" : -118.15, \"y\" : 33.80, \"spatialReference\" : {\"wkid\" : 4326}})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'reports\\\\esri_pt_business_profile.pdf'"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Create report\n",
    "pt_report = create_report(study_areas=[pt],\n",
    "                     report=\"business_loc\",\n",
    "                     export_format=\"PDF\", \n",
    "                     out_folder=r\"reports\", \n",
    "                     out_name=\"esri_pt_business_profile.pdf\")\n",
    "pt_report"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Report for a Polygon Study Area\n",
    "Let's create a polygon and use the Laborforce Profile `business_loc` report to `enrich()` our polygon."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Create polygon geometry\n",
    "from arcgis.geometry import Polygon\n",
    "poly = Polygon({\"rings\":[[[-117.26,32.81],[-117.40,32.92],[-117.12,32.80],[-117.26,32.81]]],\n",
    "                \"spatialReference\":{\"wkid\":4326}})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'reports\\\\esri_poly_business_profile.pdf'"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Create report\n",
    "poly_report = create_report(study_areas=[poly],\n",
    "                     report=\"business_loc\",\n",
    "                     export_format=\"PDF\", \n",
    "                     out_folder=r\"reports\", \n",
    "                     out_name=\"esri_poly_business_profile.pdf\")\n",
    "poly_report"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Customizing Reports"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Reports can be customized by specifying optional paramaters. Report header can be customzied to include title, subtitle and logo etc. Parameters can also be specified to explicitly call the country or dataset to query. Let's look at some examples of customizing reports."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Using `report_fields`\n",
    "\n",
    "Optional parameter `report_fields` specifies additional choices to customize reports. For example, the title, subtitle, logo, etc., which appear in the header of a report can be customized with this parameter. Let's look at an example by customizing report title, subtitle and logo."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Define report fields\n",
    "custom_fields={\"title\": \"My Report\",\n",
    "               \"subtitle\": \"Produced by My Company\"}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'reports\\\\customFields_business_summary.pdf'"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Create report\n",
    "customFields_report = create_report(study_areas=[\"380 New York Street, Redlands, CA\"],\n",
    "                     report=\"business_summary\",\n",
    "                     export_format=\"PDF\",\n",
    "                     report_fields= custom_fields,\n",
    "                     out_folder=r\"reports\", \n",
    "                     out_name=\"customFields_business_summary.pdf\")\n",
    "customFields_report"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here is a snapshot of how custom fields (highlighted in red boxes) look like in a report.\n",
    "<img src=\"../../static/img/geoenrich_custom_sample.jpg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Using `use_data`\n",
    "\n",
    "In order to explicitly call the country or dataset to query, the `use_data` parameter can be specified. This parameter can be specified to provide an additional \"performance hint\" to the service.\n",
    "\n",
    "By default, the service will automatically determine the country or dataset that is associated with each location or area submitted in the `study_areas` parameter. Narrowing down the query to a specific dataset or country through this parameter will potentially improve response time.\n",
    "\n",
    "Let's look at an example of how `use_data` is used to indicate to the service that all input features in the `study_areas` parameter describe locations or areas only discoverable in the  U.S. `USA_ESRI_2024` dataset."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Define data\n",
    "useData={\"sourceCountry\":\"US\",\"dataset\":\"USA_ESRI_2024\"}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'reports\\\\useData_business_summary.xlsx'"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Create report\n",
    "useData_report = create_report(study_areas=[\"380 New York Street, Redlands, CA\"],\n",
    "                     report=\"business_summary\",\n",
    "                     export_format=\"XLSX\",\n",
    "                     use_data= useData,\n",
    "                     out_folder=r\"reports\", \n",
    "                     out_name=\"useData_business_summary.xlsx\")\n",
    "useData_report"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Conclusion"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In this part of the `arcgis.geoenrichment` module guide series, you saw how GeoEnrichment also enables you to create different types of high quality reports. You explored the `reports` property of a `Country` object to list available reports. You experienced, in detail, how `create_report` method allows you to create rich reports for various study areas. Towards the end, you saw how these reports can be customized as well.\n",
    "\n",
    "In the next and final page, you will learn about Standard Geography Queries."
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.0"
  },
  "livereveal": {
   "scroll": true
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": true,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": true,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "274px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
